package com.intellagric.controller.module.trace_field;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TraceFieldType;
import com.intellagric.service.traceability.trace_field.FieldTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/9
 * @DESC： 场地类型信息管理
 */
@Controller
public class FieldTypeController {

    @Autowired
    private FieldTypeService fieldTypeService;

    /**
     * 添加场地信息
     * @Param 
     * @return ResponseMessage
     */
    @RequestMapping("/field/type/add")
    @ResponseBody
    public ResponseMessage add(TraceFieldType fieldType) {
        fieldType.setId(UUID.randomUUID().toString().replaceAll("-",""));
        fieldType.setCreateDate(new Date());
        fieldType.setUpdateDate(new Date());
        return fieldTypeService.addFieldType(fieldType);
    }

    /**
     * 删除场地信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/field/type/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return fieldTypeService.deleteFieldType(id);
    }

    /**
     * 修改场地信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/field/type/edit")
    @ResponseBody
    public ResponseMessage edit(TraceFieldType fieldType) {
        fieldType.setUpdateDate(new Date());
        return fieldTypeService.editFieldType(fieldType);
    }

    /**
     * 查询场地信息
     * @return TraceFieldType
     */
    @RequestMapping("/field/type/{id}")
    @ResponseBody
    public TraceFieldType get(@PathVariable String id) {
        return fieldTypeService.getFieldTypeById(id);
    }

    /**
     * 查询场地树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return fieldTypeService.getFieldTypeTree();
    }
    /**
     * 查询场地树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/treeByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getTree(String createBy) {
        return fieldTypeService.getFieldTypeTree(createBy);
    }


    /**
     * 查询场地树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/tree/select")
    @ResponseBody
    public List<TraceFieldType> getTreeSelect() {
        return fieldTypeService.getFieldTypeTree().getData();
    }

    /**
     * 查询场地树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/tree/selectByCreateBy")
    @ResponseBody
    public List<TraceFieldType> getTreeSelect(String createBy) {
        return fieldTypeService.getFieldTypeTree(createBy).getData();
    }
    /**
     * 查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return fieldTypeService.getFieldTypeList();
    }

    /**
     * 异步查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/type/sub")
    @ResponseBody
    public LayuiDataGridResult getByParentId(String parentId) {
        return fieldTypeService.getFieldTypeByParentId(parentId);
    }

}
